<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Main/Main.Master" AutoEventWireup="true"
    CodeBehind="Messages.aspx.cs" Inherits="OrganizedIN.UI.GroupContact.Messages" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .Header
        {
            background: #6D84B4;
            border: 1px solid #3B5998;
            color: white;
            font-size: 14px;
            font-weight: bold;
            margin: 0px;
            display: block;
            height: 25px;
            width: 99%;
        }
        .Header a, a:hover
        {
            color: white;
            font-size: 14px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Header a:hover
        {
            color: white;
            font-size: 14px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Content
        {
            border: 1px solid #3B5998;
            width: 99%;
        }
        .link
        {
            text-decoration: none;
            color: #6D84B4;
            font-size: 11px;
            font-weight: bold;
        }
        .link:hover
        {
            text-decoration: underline;
            color: #6D84B4;
            font-size: 11px;
            font-weight: bold;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type="text/javascript">
        $(document).ready(function() {
            try {
                $("[id$=GroupThreadPanel]").scrollTop(document.body.scrollHeight);
                $("[id$=ContactThreadPanel]").scrollTop(document.body.scrollHeight);
            }
            catch (e) { }
        });
    </script>
<div id="middle_tab" style="margin-left:20px">
  	<div id="middle_tab_title" align="center">Messages</div>
	<div class="middle_tab_content">
	<br />
	<br />
    <asp:SqlDataSource ID="dsGroupRepeater" runat="server" ConnectionString="<%$ ConnectionStrings:OrganizedInConnectionString %>"
        SelectCommand="GetGroupMessageSumary" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:SessionParameter Name="Uname" SessionField="UserID" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:Accordion ID="Accordion1" runat="server" SelectedIndex="0" FadeTransitions="true"
        FramesPerSecond="40" TransitionDuration="250" AutoSize="None" ContentCssClass="Content"
        HeaderCssClass="Header">
        <Panes>
            <asp:AccordionPane runat="server" ID="apExisting">
                <Header>
                    <a href="" onclick="return false;">Group Messages</a>
                </Header>
                <Content>
                    <table width="100%">
                        <tr>
                            <td>
                                <a href="" id="lnkGroupShow" class="link" onclick="$('#GroupcomposeMessage').slideToggle('slow');$('#lnkGroupShow').slideToggle('slow');return false;">
                                    Compose Message </a>
                                <table width="100%" id="GroupcomposeMessage" style="display: none">
                                    <tr>
                                        <td width="15%">
                                            <b>Select Group</b>
                                        </td>
                                        <td colspan="2">
                                            <asp:DropDownList ID="ddlGroup" Width="200px" runat="server" DataSourceID="dsGroups"
                                                DataTextField="Group_Name" DataValueField="Group_ID">
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="rfvGroupname" runat="server" ValidationGroup="Gcompose"
                                                ErrorMessage="* Select Group" Display="Dynamic" InitialValue="- Select -" ControlToValidate="ddlGroup"></asp:RequiredFieldValidator>
                                            <asp:SqlDataSource ID="dsGroups" runat="server" ConnectionString="<%$ ConnectionStrings:OrganizedInConnectionString %>"
                                                SelectCommand="SELECT     0 AS Group_ID, '- Select -' AS Group_Name, 0 AS SortOrder
UNION
SELECT     Group_Master.Group_ID, Group_Master.Group_Name, 1 AS SortOrder
FROM         Group_Master INNER JOIN
                      User_Organizer_Mapping ON Group_Master.Organizer_User_MappingID = User_Organizer_Mapping.Organizer_User_MappingID
WHERE     (User_Organizer_Mapping.username = @Uname)
UNION
SELECT     Group_Contact_Mappin.Group_ID, Group_Master_1.Group_Name, 1 AS SortOrder
FROM         Group_Contact_Mappin INNER JOIN
                      Group_Master AS Group_Master_1 ON Group_Contact_Mappin.Group_ID = Group_Master_1.Group_ID INNER JOIN
                      User_Organizer_Mapping AS User_Organizer_Mapping_1 ON 
                      Group_Master_1.Organizer_User_MappingID = User_Organizer_Mapping_1.Organizer_User_MappingID
WHERE     (Group_Contact_Mappin.Approved = 1) AND (User_Organizer_Mapping_1.username = @Uname)
ORDER BY SortOrder, Group_Name">
                                                <SelectParameters>
                                                    <asp:SessionParameter Name="Uname" SessionField="UserID" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="15%">
                                            <b>Enter Message</b>
                                        </td>
                                        <td colspan="2">
                                            <asp:TextBox ID="txtGMessage" TextMode="MultiLine" Width="80%" Rows="3" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="rfvGMeassage" runat="server" ValidationGroup="Gcompose"
                                                ErrorMessage="*" Display="Dynamic" ControlToValidate="txtGMessage"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                        </td>
                                        <td colspan="2">
                                            <asp:Button ID="btnSendGroupMessage" runat="server" Text="Send Message" ValidationGroup="Gcompose"
                                                OnClick="btnSendGroupMessage_Click" />
                                            <a href="" style="float: right" class="link" id="A2" onclick="$('#GroupcomposeMessage').slideToggle('slow');$('#lnkGroupShow').slideToggle('slow');return false;">
                                                Hide Composition </a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Panel ID="GroupViewPanel" runat="server">
                                    <asp:Repeater ID="rptrGroups" runat="server" OnItemCommand="rptrGroups_ItemCommand"
                                        DataSourceID="dsGroupRepeater">
                                        <HeaderTemplate>
                                            <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <tr>
                                                <td width="85%">
                                                    <table width="100%">
                                                        <tr>
                                                            <td>
                                                                <a href='<%# String.Format("Group.aspx?GroupID={0}",Eval("Group_ID")) %>'>
                                                                    <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Group_Name") %>' Font-Bold="True"
                                                                        Font-Size="12px" ForeColor="#6D84B4"></asp:Label>
                                                                </a>
                                                                <asp:Label ID="lblUnreadCount" runat="server" Text='<%# Eval("Counts") %>' Font-Bold="True"
                                                                    Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td align="center" valign="middle" style="border-left-style: solid; border-left-width: 1px;
                                                    border-left-color: #000000">
                                                    <asp:ImageButton ID="btnViewThread" runat="server" CommandArgument='<%# Eval("Group_ID") %>'
                                                        CommandName="select" ImageUrl="~/images/Message-Icon.jpg" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="height: 1px; background-color: Black">
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                </asp:Panel>
                                <asp:Panel ID="GroupThreadPanel" runat="server" Visible="false" style="height:800px;overflow:auto">
                                    <asp:Repeater ID="rptrGroupThread" runat="server" OnItemCommand="rptrGroupThread_ItemCommand"
                                        OnItemDataBound="rptrGroupThread_ItemDataBound">
                                        <HeaderTemplate>
                                                <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <tr>
                                                <td width="20%" valign="middle">
                                                    <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>' style="padding-left: 10px">
                                                        <asp:Image ID="Image1" runat="server" ToolTip='<%# Eval("Name") %>' Style="display: inline"
                                                            ImageUrl='<%# Eval("ProfilePicture") %>' Height="60px" Width="50px" /><br />
                                                        <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                            Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                    </a>
                                                </td>
                                                <td valign="top" style="padding-top: 10px">
                                                    <asp:Label ID="lblMessage" runat="server" Text='<%# Eval("Message") %>' Font-Size="11px"></asp:Label>
                                                </td>
                                                <td width="5%" valign="middle">
                                                    <asp:ImageButton ID="btnDelete" runat="server" Visible='<%# Eval("IsOwner") %>' CommandArgument='<%# Eval("MessageID") %>'
                                                        CommandName="delete" ImageUrl="~/images/brights-brights_icons-delete.ico-96x96.png"
                                                        Width="16px" Height="16px" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="3" style="height: 1px; background-color: #CCCCCC">
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <tr>
                                                <td>
                                                </td>
                                                <td colspan="2">
                                                    <asp:TextBox ID="txtGMessage" TextMode="MultiLine" Width="80%" Rows="3" runat="server"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="rfvMessage" runat="server" ValidationGroup="cmpg"
                                                        ErrorMessage="*" Display="Dynamic" ControlToValidate="txtGMessage"></asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                </td>
                                                <td colspan="2">
                                                    <asp:Button ID="btnGroupSendmsg" runat="server" CommandName="send" Text="Send Message"
                                                        ValidationGroup="cmpg" />
                                                </td>
                                            </tr>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                    <asp:LinkButton ID="lnkGBack" runat="server" CssClass="link" OnClick="lnkGBack_Click"><< Back to All Groups View</asp:LinkButton>
                                </asp:Panel>
                            </td>
                        </tr>
                    </table>
                </Content>
            </asp:AccordionPane>
            <asp:AccordionPane runat="server" ID="apSearch">
                <Header>
                    <a href="" onclick="return false;">Contact Messages</a>
                </Header>
                <Content>
                    <table width="100%">
                        <tr>
                            <td>
                                <a href="" id="lnkShow" class="link" onclick="$('#composeMessage').slideToggle('slow');$('#lnkShow').slideToggle('slow');return false;">
                                    Compose Message </a>
                                <table width="100%" id="composeMessage" style="display: none">
                                    <tr>
                                        <td width="15%">
                                            <b>Select Contact</b>
                                        </td>
                                        <td colspan="2">
                                            <asp:DropDownList ID="ddlContact" Width="200px" runat="server" DataSourceID="dsContacts"
                                                DataTextField="Name" DataValueField="username">
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="rfvContact" runat="server" ValidationGroup="compose"
                                                ErrorMessage="* Select Contact" Display="Dynamic" InitialValue="- Select -" ControlToValidate="ddlContact"></asp:RequiredFieldValidator>
                                            <asp:SqlDataSource ID="dsContacts" runat="server" ConnectionString="<%$ ConnectionStrings:OrganizedInConnectionString %>"
                                                SelectCommand="SELECT '- Select -' AS Name, '- Select -' AS username, 0 AS SortOrder UNION SELECT COALESCE (UserInformation.FirstName, '') + ' ' + COALESCE (UserInformation.LastName, '') AS Name, UserInformation.username, 1 AS SortOrder FROM Contact INNER JOIN UserInformation ON Contact.ToUName = UserInformation.username WHERE (Contact.FromUName = @Uname) and Contact.Rejected = 0 ORDER BY SortOrder, Name">
                                                <SelectParameters>
                                                    <asp:SessionParameter Name="Uname" SessionField="UserID" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="15%">
                                            <b>Enter Message</b>
                                        </td>
                                        <td colspan="2">
                                            <asp:TextBox ID="txtUMessage" TextMode="MultiLine" Width="80%" Rows="3" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="rfvMessage" runat="server" ValidationGroup="compose"
                                                ErrorMessage="*" Display="Dynamic" ControlToValidate="txtUMessage"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                        </td>
                                        <td colspan="2">
                                            <asp:Button ID="btnSendmsg" runat="server" Text="Send Message" ValidationGroup="compose"
                                                OnClick="btnSendmsg_Click" />
                                            <a href="" style="float: right" class="link" id="lnkHide" onclick="$('#composeMessage').slideToggle('slow');$('#lnkShow').slideToggle('slow');return false;">
                                                Hide Composition </a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Panel ID="ContactViewPanel" runat="server">
                                    <asp:Repeater ID="rptrUsers" runat="server" OnItemCommand="rptrUsers_ItemCommand">
                                        <HeaderTemplate>
                                            <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <tr>
                                                <td width="85%">
                                                    <table width="100%">
                                                        <tr>
                                                            <td rowspan="3" width="10%">
                                                                <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                    <asp:Image ID="Image1" runat="server" ToolTip='<%# Eval("Name") %>' Style="display: inline"
                                                                        ImageUrl='<%# Eval("ProfilePicture") %>' Height="60px" Width="50px" />
                                                                </a>
                                                            </td>
                                                            <td>
                                                                <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                    <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                                        Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                                </a>
                                                                <asp:Label ID="lblUnreadCount" runat="server" Text='<%# Eval("UnreadCount") %>' Font-Bold="True"
                                                                    Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td align="center" valign="middle" style="border-left-style: solid; border-left-width: 1px;
                                                    border-left-color: #000000">
                                                    <asp:ImageButton ID="btnViewThread" runat="server" CommandArgument='<%# Eval("username") %>'
                                                        CommandName="select" ImageUrl="~/images/Message-Icon.jpg" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="height: 1px; background-color: Black">
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                </asp:Panel>
                                <asp:Panel ID="ContactThreadPanel" runat="server" Visible="false" style="height:800px;overflow:auto">
                                    <asp:Repeater ID="rptrContactThread" runat="server" OnItemCommand="rptrContactThread_ItemCommand"
                                        OnItemDataBound="rptrContactThread_ItemDataBound">
                                        <HeaderTemplate>
                                                <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <tr>
                                                <td width="20%" valign="middle" style='<%# GetBGColor(Eval("IsRead"),Eval("IsOwn")) %>'>
                                                    <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>' style="padding-left: 10px">
                                                        <asp:Image ID="Image1" runat="server" ToolTip='<%# Eval("Name") %>' Style="display: inline"
                                                            ImageUrl='<%# Eval("ProfilePicture") %>' Height="60px" Width="50px" /><br />
                                                        <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                            Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                    </a>
                                                </td>
                                                <td valign="top" style='<%# GetBGColor(Eval("IsRead"),Eval("IsOwn")) %>'>
                                                    <asp:Label ID="lblMessage" runat="server" Text='<%# Eval("Message") %>' Font-Size="11px"></asp:Label>
                                                </td>
                                                <td width="5%" valign="middle">
                                                    <asp:ImageButton ID="btnDelete" runat="server" CommandArgument='<%# Eval("MessageID") %>'
                                                        CommandName="delete" ImageUrl="~/images/brights-brights_icons-delete.ico-96x96.png"
                                                        Width="16px" Height="16px" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="3" style="height: 1px; background-color: #CCCCCC">
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <tr>
                                                <td>
                                                </td>
                                                <td colspan="2">
                                                    <asp:TextBox ID="txtUMessage" TextMode="MultiLine" Width="80%" Rows="3" runat="server"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="rfvMessage" runat="server" ValidationGroup="cmps"
                                                        ErrorMessage="*" Display="Dynamic" ControlToValidate="txtUMessage"></asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                </td>
                                                <td colspan="2">
                                                    <asp:Button ID="btnSendmsg" runat="server" CommandName="send" Text="Send Message"
                                                        ValidationGroup="cmps" />
                                                </td>
                                            </tr>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                    <asp:LinkButton ID="lnkBack" runat="server" CssClass="link" OnClick="lnkBack_Click"><< Back to All Contacts View</asp:LinkButton>
                                </asp:Panel>
                            </td>
                        </tr>
                    </table>
                </Content>
            </asp:AccordionPane>
        </Panes>
    </asp:Accordion>
    </div>
    </div>
</asp:Content>
